﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ConstellationShow.Function.DocData;
using System.Windows.Media.Imaging;
using System.Windows.Data;

namespace ConstellationShow.Pages
{
    public partial class Select : MyPage
    {
        bool f = false;
        static bool isLoad = false;
        public Select()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Select_Loaded);
        }

        void Select_Loaded(object sender, RoutedEventArgs e)
        {
            if (!isLoad)
            {
                d1.Value = null;
                d2.Value = null;
                isLoad = true;
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
        }

        private void Click_Ok(object sender, EventArgs e)
        {
            if (txt2.Text == "") return;
            NavigationService.Navigate(new Uri("/Pages/Core.xaml?id="+GetId(txt2.Text), UriKind.Relative));
        }

        public string[] GetData(string str)
        {
            if (str == "白羊座") return SelectData.getBaiYang();
            else if (str == "金牛座") return SelectData.getJinNiu();
            else if (str == "双子座") return SelectData.getShuangZi();
            else if (str == "巨蟹座") return SelectData.getJuXie();
            else if (str == "狮子座") return SelectData.getShiZi();
            else if (str == "处女座") return SelectData.getChuNv();
            else if (str == "天秤座") return SelectData.getTianCheng();
            else if (str == "天蝎座") return SelectData.getBaiYang();
            else if (str == "射手座") return SelectData.getBaiYang();
            else if (str == "摩羯座") return SelectData.getMoJie();
            else if (str == "水瓶座") return SelectData.getShuiPing();
            else if (str == "双鱼座") return SelectData.getShuangYu();
            return null;
        }

        public string GetImg(string str)
        {
            if (str == "白羊座") return "1.png";
            else if (str == "金牛座") return "2.png";
            else if (str == "双子座") return "3.png";
            else if (str == "巨蟹座") return "4.png";
            else if (str == "狮子座") return "5.png";
            else if (str == "处女座") return "6.png";
            else if (str == "天秤座") return "7.png";
            else if (str == "天蝎座") return "8.png";
            else if (str == "射手座") return "9.png";
            else if (str == "摩羯座") return "10.png";
            else if (str == "水瓶座") return "11.png";
            else if (str == "双鱼座") return "12.png";
            return "";
        }

        public int GetId(string str)
        {
            if (str == "白羊座") return 0;
            else if (str == "金牛座") return 1;
            else if (str == "双子座") return 2;
            else if (str == "巨蟹座") return 3;
            else if (str == "狮子座") return 4;
            else if (str == "处女座") return 5;
            else if (str == "天秤座") return 6;
            else if (str == "天蝎座") return 7;
            else if (str == "射手座") return 8;
            else if (str == "摩羯座") return 9;
            else if (str == "水瓶座") return 10;
            else if (str == "双鱼座") return 11;
            return -1;
        }

        private void DatePicker_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
        {
            if (d1.Value == null) return;
            if (f) { f = false; return; }

            txt1.Text = "日一二三四五六 ".Substring((int)d1.Value.Value.DayOfWeek, 1);
            txt2.Text = Com.ConvCons(d1.Value.Value);
            string[] strs = GetData(txt2.Text);
            txt3.Text = strs[3].Replace("守护星：", "");
            txt4.Text = strs[4].Replace("守护神：", "");
            txt5.Text = strs[5].Replace("属　性：", "");
            img.Source = new BitmapImage(new Uri("/Images/" + GetImg(txt2.Text), UriKind.Relative));
            f = true;
            ConstellationShow.ConvChineseData.ChineseCalendar cc=
                new ConstellationShow.ConvChineseData.ChineseCalendar(d1.Value.Value);
            d2.Value = new DateTime(cc.ChineseYear,cc.ChineseMonth,cc.ChineseDay);
        }

        private void DatePicker_ValueChanged_1(object sender, DateTimeValueChangedEventArgs e)
        {
            if (d2.Value == null) return;
            if (f) { f = false; return; }
            txt1.Text = "日一二三四五六 ".Substring((int)DataStr2.date2.DayOfWeek, 1);
            txt2.Text = Com.ConvCons(DataStr2.date2);
            string[] strs = GetData(txt2.Text);
            txt3.Text = strs[3].Replace("守护星：", "");
            txt4.Text = strs[4].Replace("守护神：", "");
            txt5.Text = strs[5].Replace("属　性：", "");
            img.Source = new BitmapImage(new Uri("/Images/" + GetImg(txt2.Text), UriKind.Relative));
            f = true;
            d1.Value = new ConstellationShow.ConvChineseData.ChineseCalendar(
                DataStr2.date2.Year, DataStr2.date2.Month, DataStr2.date2.Day, false).DateObject;
        }
    }


}